package cn.whit.blog.service.impl;

import java.sql.SQLException;
import java.util.List;

import cn.whit.blog.dao.TblogtypeDao;
import cn.whit.blog.domain.Tblogtype;
import cn.whit.blog.domain.User;
import cn.whit.blog.service.TblogtypeService;
import cn.whit.blog.util.BeanFactory;
import cn.whit.blog.util.DynamicQuery;
import cn.whit.blog.util.PageModel;

public class TblogtypeServiceImpl implements TblogtypeService{
	
	TblogtypeDao tblogtypeDao = (TblogtypeDao)BeanFactory.createObject("tblogtypeDao");
	
	@Override
	public Tblogtype findById(String id) throws SQLException {
		return tblogtypeDao.findById(id);
	}

	@Override
	public List<Tblogtype> findAll() throws SQLException {
		return tblogtypeDao.findAll();
	}

//	@Override
//	public List<Tblogtype> findAllWithPageAndQuery(int startIndex, int pageSize, DynamicQuery query) throws Exception {
//		return tblogtypeDao.findAllWithPageAndQuery(startIndex, pageSize, query);
//	}

	@Override
	public int findTotalRecordsAndQuery(DynamicQuery query) throws Exception {
		return tblogtypeDao.findTotalRecordsAndQuery(query);
	}

	@Override
	public void save(Tblogtype tblogtype) throws SQLException {
		tblogtypeDao.save(tblogtype);
	}

	@Override
	public void update(Tblogtype tblogtype) throws SQLException {
		tblogtypeDao.update(tblogtype);
	}

	@Override
	public void deleteById(String s) throws SQLException {
		tblogtypeDao.deleteById(s);
	}

	@Override
	public PageModel findByPageAndQuery(int startIndex, int pageSize, DynamicQuery query) throws Exception {
		//startIndex 从第一页，索引 1 开始
		int totalRecords = tblogtypeDao.findTotalRecordsAndQuery(query);
		PageModel pm = new PageModel(startIndex,totalRecords,pageSize);
		List<Tblogtype> list = tblogtypeDao.findAllWithPageAndQuery(pm.getStartIndex(),pm.getPageSize(),query);
		pm.setList(list);
		//3_关联url
		pm.setUrl("TblogtypeServlet?method=list");
		return pm;
	}

}
